﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace G.Controls
{
    public class SearchTextBox : WatermarkTextBox
    {
        public event DoSearchHandel DoSearch;
        public SearchTextBox()
        {
            this.DefaultStyleKey = typeof(SearchTextBox);
        }
        //System.Windows.Controls.Primitives.ButtonBase btnSearch;
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            //btnSearch = this.GetTemplateChild("btnSearch") as System.Windows.Controls.Primitives.ButtonBase;
            //btnSearch.Click += new RoutedEventHandler(btnSearch_Click);
            this.KeyUp += new KeyEventHandler(SearchTextBox_KeyUp);
        }

        //void btnSearch_Click(object sender, RoutedEventArgs e)
        //{
        //    ApplyDoSearch();
        //}

        void SearchTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ApplyDoSearch();
            }
        }

        private void ApplyDoSearch()
        {
            if (this.DoSearch != null)
                DoSearch(this, new DoSearchEventArgs { SearchText = this.Text });
        }
    }
    public delegate void DoSearchHandel(object sender, DoSearchEventArgs args);
    public class DoSearchEventArgs : EventArgs
    {
        public string SearchText { get; set; }
    }
}
